﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExtAspNet;

namespace HY.WEB.SA
{
    public partial class schedu_edit : PageBase
    {

        string sid = "";
        public string us,um,tab="sch_edu";
        public BLL.SC.sch_edu jbs = new BLL.SC.sch_edu();

        protected void Page_Load(object sender, EventArgs e)
        {
            us = Session["ID"].ToString();
            um = Session["user"].ToString();
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request["sid"]))
                {
                    sid = Request["sid"].Trim();

                    hidsid.Text = sid;
                    Fill();
                    BindText(sid);
                }
             
            }

        }
        void Fill()
        {
            DataTable e;
            //岗位分类
            e = BLL.Bllbase.get_table("[school]");
            ddlschool.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlschool.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["schname"].ToString().Trim(), e.Rows[i]["schbh"].ToString().Trim()));
            }
            ddlschool.DataBind();

            DataTable d = jbs.GetList("sid=" + sid + "").Tables[0];

            ddlschool.SelectedIndex = ddlschool.Items.IndexOf(ddlschool.Items.FindByValue(d.Rows[0]["schbh"].ToString()));
            ddltype.SelectedIndex = ddltype.Items.IndexOf(ddltype.Items.FindByValue(d.Rows[0]["stype"].ToString()));
        }
     
        void BindText(string sid)
        {
            DataTable dt = jbs.GetList("sid=" + sid).Tables[0];

            if (dt.Rows.Count > 0)
            {
                hidsid.Text = dt.Rows[0]["sid"].ToString();
                hidbh.Text = dt.Rows[0]["ebh"].ToString();

                txtpro.Text = dt.Rows[0]["spro"].ToString();
                txtm.Text = dt.Rows[0]["mnum"].ToString();

                txtf.Text = dt.Rows[0]["fnum"].ToString();
                txtyear.Text = dt.Rows[0]["fyear"].ToString();

                txtmemo.Text = dt.Rows[0]["memo"].ToString();


                string rdate = dt.Rows[0]["sdate"].ToString().Trim();
                if (rdate.Substring(0, 4) != "1900")
                {
                  DateTime   lastday = DateTime.Parse(rdate);
                  date1.Text = lastday.ToString("yyyy-M-d");
                }


                string edate = dt.Rows[0]["edate"].ToString().Trim();
                if (rdate.Substring(0, 4) != "1900")
                {
                    DateTime lastday = DateTime.Parse(edate);
                    date2.Text = lastday.ToString("yyyy-M-d");
                }
                
            
            }

        }

   


      
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Model.SC.sch_edu jb = new Model.SC.sch_edu();

            jb.sid = int.Parse(hidsid.Text);
            jb.ebh = hidbh.Text;
            
            if (jb.ebh == "") return;

            jb.schbh = ddlschool.SelectedValue;
            jb.schname = ddlschool.SelectedText;


            jb.spro = txtpro.Text;

            jb.fnum = int.Parse(txtf.Text);
            jb.mnum = int.Parse(txtm.Text);
            jb.snum = jb.fnum + jb.mnum;
            jb.fyear = txtyear.Text;

            jb.sdate = DateTime.Parse(date1.Text.Trim());
            jb.edate = DateTime.Parse(date2.Text.Trim());

            jb.stype = ddltype.SelectedValue;

            jb.memo = txtmemo.Text;


            BLL.SC.sch_edu sco = new BLL.SC.sch_edu();
            sco.Update(jb);


            //更新业务员操作记录
            BLL.Bllbase.update_rec(tab, um, " ebh='" + jb.ebh + "' ");


            Alert.Show("修改完成 ");
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
       
        }

       
    }
}